<?php 
class ControllerAccountPrecreate extends Controller {
	private $error = array();
	      
  	public function index() {
		if ($this->customer->isLogged()) {
	  		$this->redirect(HTTPS_SERVER . 'index.php?route=account/account');
    	}
		
		
		
    	$this->language->load('account/precreate');
		$this->document->title = $this->language->get('heading_title');
		
		$this->data['account_id'] = $this->config->get('config_account_id');
        $this->data['privacy_id'] = $this->config->get('config_privacy_id');
		$this->load->model('catalog/syscontent');
		
		$syscontent_info1 = $this->model_catalog_syscontent->getSyscontent($this->config->get('config_account_id'));
		$this->data['title1'] = html_entity_decode($syscontent_info1['title']);
		$this->data['description1'] = html_entity_decode($syscontent_info1['description']);
		
		$syscontent_info2 = $this->model_catalog_syscontent->getSyscontent($this->config->get('config_privacy_id'));
		$this->data['title2'] = html_entity_decode($syscontent_info2['title']);
		$this->data['description2'] = html_entity_decode($syscontent_info2['description']);
		
		$this->load->model('account/customer');
		
		if (($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validate()) ) {
		$this->redirect(HTTPS_SERVER . 'index.php?route=account/create');
		}
		
		
      	$this->document->breadcrumbs = array();

      	$this->document->breadcrumbs[] = array(
        	'href'      => HTTP_SERVER . 'index.php?route=common/home',
        	'text'      => $this->language->get('text_home'),
        	'separator' => FALSE
      	); 

      	$this->document->breadcrumbs[] = array(
        	'href'      => HTTPS_SERVER . 'index.php?route=account/account',
        	'text'      => $this->language->get('text_account'),
        	'separator' => $this->language->get('text_separator')
      	);
		
      	$this->document->breadcrumbs[] = array(
        	'href'      => HTTPS_SERVER . 'index.php?route=account/precreate',
        	'text'      => $this->language->get('text_precreate'),
        	'separator' => $this->language->get('text_separator')
      	);
		
    	$this->data['heading_title'] = $this->language->get('heading_title');


				
		

		$this->data['button_continue'] = $this->language->get('button_continue');
    
		if (isset($this->error['join_agree'])) {
			$this->data['error_join_agree'] = $this->error['join_agree'];
		} else {
			$this->data['error_join_agree'] = '';
		}
		
		if (isset($this->error['info_agree'])) {
			$this->data['error_info_agree'] = $this->error['info_agree'];
		} else {
			$this->data['error_info_agree'] = '';
		}
		
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/precreate.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/account/precreate.tpl';
		} else {
			$this->template = 'default/template/account/precreate.tpl';
		}
		
		$this->children = array(
			'common/column_right',
			'common/footer',
			'common/column_left',
			'common/header'
		);

		$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));	
  	}
	
	public function validate() {
	
	
		if ($this->request->post['join_agree'] != 1) {
      		$this->error['join_agree'] = $this->language->get('error_join_agree');
    	}
		
		if ($this->request->post['info_agree'] != 1) {
      		$this->error['info_agree'] = $this->language->get('error_info_agree');
    	}
		
		
		
		
		if (!$this->error) {
      		return TRUE;
    	} else {
      		return FALSE;
    	}
	
	
	}
	
	
}
?>